package routers

import (
	"Bluebell/controller" // 千万不要忘了导入把你上一步生成的docs
	_ "Bluebell/docs"     // 千万不要忘了导入把你上一步生成的docs
	"Bluebell/logger"
	"github.com/gin-gonic/gin"
	"github.com/swaggo/files"
	gs "github.com/swaggo/gin-swagger"
	"net/http"
)

func Setup(mode string) *gin.Engine {
	if mode == gin.ReleaseMode {
		gin.SetMode(gin.ReleaseMode)
	}

	r := gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true))

	r.GET("/swagger/*any", gs.WrapHandler(swaggerFiles.Handler))
	//用户功能

	//r.LoadHTMLFiles("templates/index.html")
	//r.Static("/static", "./static")
	r.GET("/", func(context *gin.Context) {
		context.HTML(http.StatusOK, "index.html", nil)
	})
	api := r.Group("/api/v1")
	{
		//注册
		api.POST("/signup", controller.RegisterHandler)
		//登录
		api.POST("/login", controller.LoginHandler)
		//使用jwt中间件
		//api.Use(middleware.JWTAuthMiddleware())
		//获取分类下来列表
		api.GET("/community", controller.CommunityHandler)
		api.GET("/community/:id", controller.CommunityDetailHandler)
		api.POST("/post", controller.CreatePostHandler)
		api.GET("/post/:id", controller.GetPostDetailHandler)
		api.GET("/posts", controller.GetPostListHandler)
		api.POST("/vote", controller.PostVoteHandler)
		api.GET("/posts2", controller.GetPostListHandler2)
	}
	return r
}
